Handling of Missing Data
A requested property that an object does not have is returned as null in JSON (None after decoding into Python). Reading or sorting by that property does not create it. For example, asking for origin returns "origin": null for an apple with no origin property.
Comparisons and sorting
Operation | Result |
|---|---|
| Matches an unset |
| Does not match an unset |
| Matches an unset |
| Does not match an unset |
Ascending / descending sort | Unset values appear first / last, respectively. |
An absent property is treated as an unset value whether the property exists on other objects or has never been stored in the database. For constraint comparisons, unset values are neither less than nor greater than non-null values. Sorting uses a different ordering, placing unset values below non-null values. See constraints, sort, and results for the complete query options.
Returning a missing property
This request adds two apple entities. Both have color and type properties; only the green apple has an origin:
Query:
[{
"AddEntity": {
"class": "Apple_3",
"properties": {
"color": "green",
"type": "granny_smith",
"origin": "Allen, Neuquen, Argentina"
}
}
}, {
"AddEntity": {
"class": "Apple_3",
"properties": {
"color": "red",
"type": "granny_smith"
}
}
}]
Response:
[{
"AddEntity": {
"status": 0
}
}, {
"AddEntity": {
"status": 0
}
}]
The following query requests the same three properties from both entities:
Query:
[{
"FindEntity": {
"with_class": "Apple_3",
"results": {
"list": ["color", "type", "origin"]
}
}
}]
Response:
[{
"FindEntity": {
"entities": [{
"color": "green",
"origin": "Allen, Neuquen, Argentina",
"type": "granny_smith"
}, {
"color": "red",
"origin": null,
"type": "granny_smith"
}],
"returned": 2,
"status": 0
}
}]
The red apple has no origin property, so its response contains "origin": null.
Sorting by a missing property
The next two queries assume that Apple_1 and Apple_2 each contain two apple entities with color and type properties. The first query sorts by IQ, a property absent from every matching entity. The query succeeds and returns null for the requested missing property. Equal sort values use ascending object IDs.
Query:
[{
"FindEntity": {
"with_class": "Apple_1",
"sort": "IQ",
"results": {
"list": ["color", "type", "IQ"]
}
}
}]
Response:
[{
"FindEntity": {
"entities": [{
"IQ": null,
"color": "red",
"type": "granny_smith"
}, {
"IQ": null,
"color": "green",
"type": "granny_smith"
}],
"returned": 2,
"status": 0
}
}]
If a property unexpectedly returns null, check its spelling and whether it was added to those objects. Omitting IQ from the requested output leaves the sort behavior unchanged:
Query:
[{
"FindEntity": {
"with_class": "Apple_2",
"sort": "IQ",
"results": {
"list": ["color", "type"]
}
}
}]
Response:
[{
"FindEntity": {
"entities": [{
"color": "red",
"type": "granny_smith"
}, {
"color": "green",
"type": "granny_smith"
}],
"returned": 2,
"status": 0
}
}]
Finding objects with a missing property
A comparison with null selects objects where a property is absent. In this example, the Apple_5 class contains a red apple with no origin property:
[{
"FindEntity": {
"with_class": "Apple_5",
"constraints": ["$origin", "==", null],
"results": {
"list": ["color", "type", "origin"]
}
}
}]
Response:
[{
"FindEntity": {
"entities": [{
"color": "red",
"origin": null,
"type": "granny_smith"
}],
"returned": 1,
"status": 0
}
}]